package nina.yiyou.performance.s20confirm.compute

import nina.yiyou.salary.process.salary.ComputeMapMaker

import java.nio.file.Path

class S2ComputeMapMaker {

  S2ComputeMapMaker(Map basicMap, Map performMap, Path outDir, Path tmpDir) {
    _basicMap = basicMap
    _performMap = performMap
    _outDir = outDir
    _tmpDir = tmpDir
  }

  Map make() {
    return new ComputeMapMaker([
        [_basicMap, this.&computeBasic],
        [_performMap, this.&computePerformance],
    ]).make()
  }

  private Map computeBasic(Map line) {
    String name = ['工号', '部门', '姓名'].collect { line[it] }.join('_') + '_'
    return [
        '路径.excel': _outDir.resolve(name + '.xlsx'),
        '路径.data' : _tmpDir.resolve(name + '.csv'),
    ]
  }

  private Map computePerformance(Map line) {
    def total = ['业绩', '能力', '态度', '考勤'].collect { line[it] ?: 0 }.sum() as double
    String rank = [
        [96, 'S'],
        [90, 'A'],
        [80, 'B'],
        [70, 'C'],
        [60, 'D'],
        [Integer.MIN_VALUE, 'E'],
    ].findAll { total >= (it[0] as int) }.max { it[0] }[1]

    return [
        '绩效总分': total,
        '绩效评价': rank,
    ]
  }

  private final Map _basicMap
  private final Map _performMap

  private final Path _outDir
  private final Path _tmpDir
}
